#!/usr/bin/env python
'''
Created on Nov 2, 2010

@author: linh-cl
'''

from widgets.MyTreeWidget import MyTreeWidget
from types import NoneType
import sip
from mercurial.commands import cat
from form.CategoryDialog import CategoryDialog
sip.setapi( 'QString', 2 )
from util.NoteManager import NoteManager
from util.CategoryManager import CategoryManager
from core.Category import Category
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.Qt import *
from resource import qrc_resource
from pysqlite2 import dbapi2 as sqlite

class MainForm( QMainWindow ):
  def __init__( self , conn = None ):
    super( MainForm, self ).__init__()
    #variables
    self.conn = conn
    self.notesChanged = False
    #set title
    self.setWindowTitle( "All my notes" )
    #set icon
    self.setWindowIcon( QIcon( ':/note.png' ) )
    #set minimum size
    self.setMinimumSize( 800, 600 )
    #make window center in screen
    self.initWindow()
    #init actions
    self.createAction()
    #init menu bar
    self.createMenuBar()
    #init tool bars
    self.createToolBar()
    #init status bar
    self.createStatusBar()
    #init dock widgets
    #self.createDockWindows()
    self.createElements()
    #set button state
    self.updateButtonsState()
  '''
  @fn initWindow
  @brief init window size
  '''
  def initWindow( self ):
    #set maximize size is equal to screen size
    self.setMaximumSize( QDesktopWidget().screenGeometry().width(), QDesktopWidget().screenGeometry().height() )
    #set size policy
    self.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Expanding )
    #set maximize state
    #self.setWindowState( Qt.WindowMaximized )
    self.setWindowFlags( self.windowFlags() | Qt.WindowMaximizeButtonHint | Qt.WindowMinimizeButtonHint )
    self.setWindowFlags( self.windowFlags() & ~Qt.MSWindowsFixedSizeDialogHint )
    screen = QDesktopWidget().screenGeometry()
    size = self.geometry()
    self.move( ( screen.width() - size.width() ) / 2, ( screen.height() - size.height() ) / 2 )
  '''
  @fn createAction
  @brief init actions
  '''
  def createAction( self ):
    #file menu actions
    self.newNoteAct = QAction( QIcon( ':/note-new.png' ), "&New note", self, shortcut = "Ctrl+N",
                               statusTip = "Create new note", triggered = self.newNote )
    self.editNoteAct = QAction( QIcon( ':/note-edit.png' ), "&Edit note", self, shortcut = "Ctrl+E",
                                statusTip = "Edit note", triggered = self.editNote )
    self.deleteNoteAct = QAction( QIcon( ':/note-delete.png' ), "&Delete note", self, shortcut = "Del",
                                 statusTip = "Delete note", triggered = self.deleteNote )
    self.saveNoteAct = QAction( QIcon( ':/save.png' ), "&Save note", self, shortcut = "Ctrl+S",
                               statusTip = "Save note", triggered = self.saveNote )
    self.importAct = QAction ( QIcon( ':/import.png' ), "&Import", self, shortcut = "Ctrl+Alt+I", statusTip = "Import other notes" , triggered = self.importNotes )
    self.exportAct = QAction( QIcon( ':/export.png' ), "&Export", self, shortcut = "Ctrl+Alt+E", statusTip = "Export notes" , triggered = self.exportNotes )
    self.quitAct = QAction( "&Quit", self, shortcut = "Ctrl+Q", statusTip = "Quit the application", triggered = self.closeApplication )
    #edit menu actions
    self.cutAct = QAction( QIcon( ':/cut.png' ), "C&ut", self, shortcut = "Ctrl+X", statusTip = "Cut selected text", triggered = self.cutSelected )
    self.copyAct = QAction ( QIcon( ':/copy.png' ), "&Copy", self, shortcut = "Ctrl+C", statusTip = "Copy selected text" , triggered = self.copySelected )
    self.pasteAct = QAction ( QIcon( ':/paste.png' ), "&Paste", self, shortcut = "Ctrl+V", statusTip = "Paste text in clipboard" , triggered = self.pasteCopyed )
    self.undoAct = QAction( QIcon( ':/undo.png' ), "&Undo", self, shortcut = "Ctrl+Z", statusTip = "Undo" , triggered = self.undoAction )
    self.redoAct = QAction ( QIcon( ':/redo.png' ), "&Redo", self, shortcut = "Ctrl+Y", statusTip = "Redo" , triggered = self.redoAction )
    self.searchNoteAct = QAction( QIcon( ':/find.png' ), "&Search", self, shortcut = "Ctrl+F", statusTip = "Search note" , triggered = self.searchAction )
    self.preferenceAct = QAction( QIcon( ':/settings.png' ), "&Preferences", self, shortcut = "Ctrl+K", statusTip = "Settings" , triggered = self.preferenceAction )
    #format menu actions
    self.fontFormatAct = QAction( QIcon( ':/font.png' ), "&Fonts", self, shortcut = "Ctrl+D", statusTip = "Font settings" , triggered = self.fontFormatAction )
    self.colorAct = QAction ( QIcon( ':/colors.png' ), "&Color", self, shortcut = "Ctrl+T", statusTip = "Set color for selected text" , triggered = self.colorFormatAction )
    self.regularAct = QAction ( QIcon( ':/normal.png' ), "&Regular", self, shortcut = "Ctrl+G", statusTip = "Set selected text to regular" , triggered = self.regularFormatAction )
    self.italicAct = QAction( QIcon( ':/italic.png' ), "&Italic", self, shortcut = "Ctrl+I", statusTip = "Set selected text to italic" , triggered = self.italicFormatAction )
    self.italicAct.setCheckable( True )
    self.boldAct = QAction( QIcon( ':/bold.png' ), "&Bold", self, shortcut = "Ctrl+B", statusTip = "Set selected text to bold" , triggered = self.boldFormatAction )
    self.boldAct.setCheckable( True )
    self.underlineAct = QAction( QIcon( ':/underline.png' ), "&Underline", self, shortcut = "Ctrl+U", statusTip = "Set selected text to underline" , triggered = self.underlineFormatAction )
    self.underlineAct.setCheckable( True )
    self.textAlignGroup = QActionGroup( None )
    self.leftAlignAct = QAction( QIcon( ':/align-left.png' ), "Align &left", self, shortcut = "Ctrl+L", statusTip = "Set current line to align left" , triggered = self.leftAlignAction )
    self.leftAlignAct.setCheckable( True )
    self.leftAlignAct.setActionGroup( self.textAlignGroup )
    self.rightAlignAct = QAction( QIcon( ':/align-right.png' ), "Align &right", self, shortcut = "Ctrl+R", statusTip = "Set current line to align right" , triggered = self.rightAlignAction )
    self.rightAlignAct.setCheckable( True )
    self.rightAlignAct.setActionGroup( self.textAlignGroup )
    self.centerAlignAct = QAction( QIcon( ':/align-center.png' ), "Align &center", self, shortcut = "Ctrl+E", statusTip = "Set current line to align center" , triggered = self.centerAlignAction )
    self.centerAlignAct.setCheckable( True )
    self.centerAlignAct.setActionGroup( self.textAlignGroup )
    self.justifyAlignAct = QAction( QIcon( ':/align-justify.png' ), "Align &justify", self, shortcut = "Ctrl+J", statusTip = "Set current line to align justify" , triggered = self.justifyAlignAction )
    self.justifyAlignAct.setCheckable( True )
    self.justifyAlignAct.setActionGroup( self.textAlignGroup )
    #category menu actions
    self.newCategoryAct = QAction( QIcon( ':/category-add.png' ), "&New category", self, shortcut = "Ctrl+Alt+N",
                                  statusTip = "Create new category", triggered = self.newCategory )
    self.editCategoryAct = QAction( QIcon( ':/category-edit.png' ), "&Edit category", self, shortcut = "Ctrl+Alt+E",
                                   statusTip = "Edit category", triggered = self.editCategory )
    self.deleteCategoryAct = QAction( QIcon( ':/category-delete.png' ), "&Delete category", self, shortcut = "Ctrl+Del",
                                     statusTip = "Delete category", triggered = self.deleteCategory )
    #help menu actions
    self.helpAct = QAction( QIcon( ':/help.png' ), "&Help", self, statusTip = "Help" , triggered = self.helpAction )
    self.aboutAct = QAction( QIcon( ':/at.png' ), "&About", self,
                            statusTip = "Show the application's About box",
                            triggered = self.about )
    self.aboutQtAct = QAction( QIcon( ':/qtlogo.png' ), "About &Qt", self,
                              statusTip = "Show the Qt library's About box",
                              triggered = qApp.aboutQt )
  '''
  @fn createMenuBar
  @brief init menu bar
  '''
  def createMenuBar( self ):
    #file menu
    self.fileMenu = self.menuBar().addMenu( "&File" )
    #note
    self.fileMenu.addAction( self.newNoteAct )
    self.fileMenu.addAction( self.editNoteAct )
    self.fileMenu.addAction( self.saveNoteAct )
    self.fileMenu.addAction( self.deleteNoteAct )
    self.fileMenu.addSeparator()
    #others
    self.fileMenu.addAction( self.importAct )
    self.fileMenu.addAction( self.exportAct )
    self.fileMenu.addSeparator()
    #exit
    self.fileMenu.addAction( self.quitAct )
    #edit menu
    self.editMenu = self.menuBar().addMenu( "&Edit" )
    self.editMenu.addAction( self.cutAct )
    self.editMenu.addAction( self.copyAct )
    self.editMenu.addAction( self.pasteAct )
    self.editMenu.addSeparator()
    self.editMenu.addAction( self.undoAct )
    self.editMenu.addAction( self.redoAct )
    self.editMenu.addSeparator()
    self.editMenu.addAction( self.searchNoteAct )
    self.editMenu.addSeparator()
    self.editMenu.addAction( self.preferenceAct )
    #format menu
    self.formatMenu = self.menuBar().addMenu( "For&mat" )
    self.formatMenu.addAction( self.fontFormatAct )
    self.formatMenu.addAction( self.colorAct )
    self.formatMenu.addSeparator()
    self.formatMenu.addAction( self.regularAct )
    self.formatMenu.addAction( self.italicAct )
    self.formatMenu.addAction( self.boldAct )
    self.formatMenu.addAction( self.underlineAct )
    self.formatMenu.addSeparator()
    self.formatMenu.addAction( self.leftAlignAct )
    self.formatMenu.addAction( self.centerAlignAct )
    self.formatMenu.addAction( self.rightAlignAct )
    self.formatMenu.addAction( self.justifyAlignAct )
    #category menu
    self.categoryMenu = self.menuBar().addMenu( "&Category" )
    self.categoryMenu.addAction( self.newCategoryAct )
    self.categoryMenu.addAction( self.editCategoryAct )
    self.categoryMenu.addAction( self.deleteCategoryAct )
    #help menu
    self.menuBar().addSeparator()
    self.helpMenu = self.menuBar().addMenu( "&Help" )
    self.helpMenu.addAction( self.helpAct )
    self.helpMenu.addAction( self.aboutAct )
    self.helpMenu.addAction( self.aboutQtAct )
  '''
  @fn createToolBar
  @brief init tool bar
  '''
  def createToolBar( self ):
    #note bar
    self.noteToolBar = self.addToolBar( "Notes" )
    self.noteToolBar.addAction( self.newNoteAct )
    self.noteToolBar.addAction( self.editNoteAct )
    self.noteToolBar.addAction( self.saveNoteAct )
    self.noteToolBar.addAction( self.deleteNoteAct )
    #edit bar
    self.editToolBar = self.addToolBar( "Edit" )
    self.editToolBar.addAction( self.cutAct )
    self.editToolBar.addAction( self.copyAct )
    self.editToolBar.addAction( self.pasteAct )
    self.editToolBar.addSeparator()
    self.editToolBar.addAction( self.undoAct )
    self.editToolBar.addAction( self.redoAct )
    self.editToolBar.addSeparator()
    self.editToolBar.addAction( self.searchNoteAct )
    #format bar
    self.formatToolBar = self.addToolBar( "Format" )
    self.formatToolBar.addAction( self.fontFormatAct )
    self.formatToolBar.addAction( self.colorAct )
    self.formatToolBar.addSeparator()
    self.formatToolBar.addAction( self.regularAct )
    self.formatToolBar.addAction( self.italicAct )
    self.formatToolBar.addAction( self.boldAct )
    self.formatToolBar.addAction( self.underlineAct )
    self.formatToolBar.addSeparator()
    self.formatToolBar.addAction( self.leftAlignAct )
    self.formatToolBar.addAction( self.centerAlignAct )
    self.formatToolBar.addAction( self.rightAlignAct )
    self.formatToolBar.addAction( self.justifyAlignAct )
    #settings bar
    self.settingToolBar = self.addToolBar( "Settings" )
    self.settingToolBar.addAction( self.preferenceAct )
  '''
  @fn createStatusBar
  @brief init status bar
  '''
  def createStatusBar( self ):
    self.statusBar().showMessage( "Ready" )
  def createElements( self ):
    #init spliters
    self.noteSplitter = QSplitter( Qt.Vertical )
    self.mainSplitter = QSplitter( Qt.Horizontal )
    #init note list table
    self.notesTable = QTableWidget( self.noteSplitter )
    self.noteSplitter.addWidget( self.notesTable )
    #init notes talbe values
    self.initNotesTable()
    #init text browser
    self.textBrowser = QTextBrowser( self.noteSplitter )
    self.noteSplitter.addWidget( self.textBrowser )
    #set signals - slots
    self.textBrowser.setReadOnly( False )
    self.connect( self.textBrowser, SIGNAL( "selectionChanged ()" ), self.textBrowserSelectedChanged )
    #init tree
    #self.catTree = QTreeWidget( self.mainSplitter )
    self.catTree = MyTreeWidget( self.conn, self.mainSplitter )
    #init tree values
    self.initCategoryTree()
    self.mainSplitter.addWidget( self.catTree )
    self.mainSplitter.addWidget( self.noteSplitter )
    self.catTree.setMaximumWidth( 200 )
    self.setCentralWidget( self.mainSplitter )
  def initCategoryTree( self ):
    self.catTree.clear()
    self.catTree.setMaximumWidth( 200 )
    self.catTree.setMinimumWidth( 100 )
    self.catTree.setColumnCount( 1 )
    self.catTree.setHeaderLabel( "Note categories" )
    self.catTree.setHeaderHidden( True )
    self.catTree.setItemsExpandable( True )
    #init data
    self.catTree.updateData( self.conn )
    #connect signal 
    self.connect( self.catTree, SIGNAL( "itemSelectionChanged(void)" ), self.catTreeSelectedChanged )
    self.connect( self.catTree, SIGNAL( "itemDoubleClicked(QTreeWidgetItem *, int)" ), self.catTreeItemDoubleClicked )
    self.connect( self.catTree, SIGNAL( "itemExpanded (QTreeWidgetItem *)" ), self.catTreeItemExpanded )
  def initNotesTable( self ):
    self.notesTable.clear()
    self.notesTable.clearContents()
    self.notesTable.setColumnCount( 5 )
    self.notesTable.setColumnWidth( 0, 290 )
    self.notesTable.setColumnWidth( 1, 95 )
    self.notesTable.setColumnWidth( 2, 135 )
    self.notesTable.setColumnWidth( 3, 50 )
    self.notesTable.setColumnWidth( 4, 45 )
    
    self.notesTable.setHorizontalHeaderLabels( ["Title", "Category", "Created date", "Read", "Rate"] )
    notesMan = NoteManager( self.conn )
    notes = notesMan.getAllNotes()
    self.showNotesTable( notes )
    #connect signal
    self.connect( self.notesTable, SIGNAL( "itemSelectionChanged ()" ), self.notesTableSelectedChanged )
  def updateButtonsState( self ):
    #---------------notes selection---------------
    hasSelected = False
    if len( self.notesTable.selectedItems() ) > 0:
      #enable some button
      hasSelected = True
    else:
      #disable all button
      hasSelected = False
    self.editNoteAct.setEnabled( hasSelected )
    self.deleteNoteAct.setEnabled( hasSelected )
    self.saveNoteAct.setEnabled( self.notesChanged )
    self.cutAct.setEnabled( hasSelected )
    self.copyAct.setEnabled( hasSelected )
    self.pasteAct.setEnabled( hasSelected )
    self.regularAct.setEnabled( hasSelected )
    self.boldAct.setEnabled( hasSelected )
    self.italicAct.setEnabled( hasSelected )
    self.underlineAct.setEnabled( hasSelected )
    self.leftAlignAct.setEnabled( hasSelected )
    self.centerAlignAct.setEnabled( hasSelected )
    self.rightAlignAct.setEnabled( hasSelected )
    self.justifyAlignAct.setEnabled( hasSelected )
    self.fontFormatAct.setEnabled( hasSelected )
    self.colorAct.setEnabled( hasSelected )
    #------------category selection --------------
    selectedItems = self.catTree.selectedItems()
    if len( selectedItems ) > 0:
      #check root
      selectedItem = self.catTree.currentItem()
      cat = selectedItem.data( 0, Qt.UserRole )
      #cast to Category type
      cat = cat.toPyObject()
      if type( cat ) is not Category:
        hasSelected = False
      else:
        hasSelected = True
    else:
      #select none
      hasSelected = False
    self.editCategoryAct.setEnabled( hasSelected )
    self.deleteCategoryAct.setEnabled( hasSelected )
  def showNotesTable( self, notes ):
    if notes is not None:
      self.notesTable.clearContents()
      self.notesTable.setRowCount( len( notes ) + 1 )
      self.notesTable.setAlternatingRowColors( True )
      self.notesTable.setEditTriggers( QTableWidget.DoubleClicked )
      self.notesTable.setSelectionBehavior( QTableWidget.SelectRows )
      self.notesTable.setSelectionMode( QTableWidget.SingleSelection )
      i = 0
      for note in notes:
        #display each note
        #title
        titleItem = QTableWidgetItem( note.get_title() )
        titleItem.setData( Qt.UserRole, QVariant( note ) )
        self.notesTable.setItem( i, 0, titleItem )
        #category
        catItem = QTableWidgetItem( note.get_category().get_name() )
        self.notesTable.setItem( i, 1, catItem )
        #created date
        ctime = note.get_create_time()
        createdItem = QTableWidgetItem( '%d-%d-%d %d:%d:%d' % ( ctime.day, ctime.month, ctime.year, ctime.hour, ctime.minute, ctime.second ) )
        self.notesTable.setItem( i, 2, createdItem )
        #read
        readItem = QTableWidgetItem( '%d' % ( note.get_read_count() ) )
        readItem.setTextAlignment( Qt.AlignRight | Qt.AlignVCenter )
        self.notesTable.setItem( i, 3, readItem )
        #rate
        rateItem = QTableWidgetItem( '%d' % ( note.get_rate() ) )
        rateItem.setTextAlignment( Qt.AlignRight | Qt.AlignVCenter )
        self.notesTable.setItem( i, 4, rateItem )
        #next row
        self.notesTable.setRowHeight( i, 20 )
        i += 1
      self.notesTable.setRowHeight( i, 20 )
    else:
      self.notesTable.clearContents()
      self.notesTable.setRowCount( 1 )
      self.notesTable.setRowHeight( 0, 20 )
  #slots
  def textBrowserSelectedChanged( self ):
    print 'selected changed'
    
  def notesTableSelectedChanged( self ):
    items = self.notesTable.selectedItems()
    if len( items ) > 0:
      curRow = self.notesTable.currentRow()
      dataItem = self.notesTable.item( curRow, 0 )
      note = dataItem.data( Qt.UserRole )
      note = note.toPyObject()
      if note is not None:
        self.textBrowser.setText( note.get_content() )
      else:
        self.textBrowser.clear()
    else:
      self.textBrowser.clear()
    self.updateButtonsState()
  def catTreeSelectedChanged( self ):
    selectedItem = self.catTree.currentItem()
    cat = selectedItem.data( 0, Qt.UserRole )
    #cast to Category type
    cat = cat.toPyObject()
    if type( cat ) is not Category:
      #root item
      notesMan = NoteManager( self.conn )
      notes = notesMan.getAllNotes()
      self.showNotesTable( notes )
    else:
      #Other items
      #get child categories and show in tree
      #clear child
      if selectedItem.childCount() > 0 :
        for i in range( selectedItem.childCount() - 1, -1, -1 ):
          chCat = selectedItem.child( i )
          selectedItem.removeChild( chCat )
      #cleaned
      catMan = CategoryManager( self.conn )
      cats = catMan.getChildCategory( cat )
      if type( cats ) is not NoneType:
        for ca in cats:
          cc = QTreeWidgetItem( selectedItem, [ca.get_name()] )
          cc.setData( 0, Qt.UserRole, QVariant( ca ) )
          #cc.setFlags( Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsDragEnabled | Qt.ItemIsDropEnabled )
          #sub level categories
          ccs = catMan.getChildCategory( ca )
          if type( ccs ) is not NoneType:
            for sc in ccs:
              si = QTreeWidgetItem( cc, [sc.get_name()] )
              si.setData( 0, Qt.UserRole, QVariant( sc ) )
              #si.setFlags( Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsDragEnabled | Qt.ItemIsDropEnabled )
      #get notes by category
      notesMan = NoteManager( self.conn )
      notes = notesMan.getNotes( category = cat )
      self.showNotesTable( notes )
    self.updateButtonsState()
  def catTreeItemExpanded ( self , item ):
    selectedItem = item
    if type( selectedItem ) is NoneType:
      return
    cat = selectedItem.data( 0, Qt.UserRole )
    #cast to Category type
    cat = cat.toPyObject()
    if type( cat ) is not Category:
      #root item
      return
    else:
      #Other items
      #get child categories and show in tree
      #clear child
      if selectedItem.childCount() > 0 :
        for i in range( selectedItem.childCount() - 1, -1, -1 ):
          chCat = selectedItem.child( i )
          selectedItem.removeChild( chCat )
      #cleaned
      catMan = CategoryManager( self.conn )
      cats = catMan.getChildCategory( cat )
      if type( cats ) is not NoneType:
        for ca in cats:
          cc = QTreeWidgetItem( selectedItem, [ca.get_name()] )
          cc.setData( 0, Qt.UserRole, QVariant( ca ) )
          #sub level categories
          ccs = catMan.getChildCategory( ca )
          if type( ccs ) is not NoneType:
            for sc in ccs:
              si = QTreeWidgetItem( cc, [sc.get_name()] )
              si.setData( 0, Qt.UserRole, QVariant( sc ) )
  def catTreeItemDoubleClicked( self ):
    curItem = self.catTree.currentItem()
    self.editCategory()
    self.catTree.updateData()
  #Actions list:(
  def newNote( self ):
    pass
  def editNote( self ):
    pass
  def saveNote( self ):
    pass
  def deleteNote( self ):
    pass
  def importNotes( self ):
    pass
  def exportNotes( self ):
    pass
  def closeApplication( self ):
    self.close()
  #edit actions
  def cutSelected( self ):
    pass
  def copySelected( self ):
    pass
  def pasteCopyed( self ):
    pass
  def undoAction( self ):
    pass
  def redoAction( self ):
    pass
  def searchAction( self ):
    pass
  def preferenceAction( self ):
    pass
  #format actions
  def fontFormatAction( self ):
    pass
  def colorFormatAction( self ):
    pass
  def regularFormatAction( self ):
    pass
  def italicFormatAction( self ):
    pass
  def boldFormatAction( self ):
    pass
  def underlineFormatAction( self ):
    pass
  def leftAlignAction( self ):
    pass
  def rightAlignAction( self ):
    pass
  def centerAlignAction( self ):
    pass
  def justifyAlignAction( self ):
    pass
  #category actions
  def newCategory( self ):
    #get current category
    curCat = self.catTree.currentItem()
    catData = curCat.data( 0, Qt.UserRole )
    cat = catData.toPyObject()
    catDlg = CategoryDialog( cat, self.conn, False )
    if catDlg.exec_():
      self.catTree.updateData()
  def editCategory( self ):
    #get current category
    curCat = self.catTree.currentItem()
    catData = curCat.data( 0, Qt.UserRole )
    cat = catData.toPyObject()
    if type( cat ) is not Category:
      return
    catDlg = CategoryDialog( cat, self.conn, True )
    if catDlg.exec_():
      self.catTree.updateData() 
  def deleteCategory( self ):
    #get current category
    curCat = self.catTree.currentItem()
    catData = curCat.data( 0, Qt.UserRole )
    cat = catData.toPyObject()
    if type( cat ) is not Category:
      return
    #confirm
    confirm = QMessageBox.question( self, "Confirm", "Are you sure to delete category: %s" % cat, buttons = QMessageBox.Yes | QMessageBox.No, defaultButton = QMessageBox.Yes )
    if confirm == QMessageBox.Yes:
      catMan = CategoryManager( self.conn )
      catMan.deleteCategory( cat )
      self.catTree.updateData()
  #help
  def helpAction( self ):
    pass
  def about( self ):
    QMessageBox.about( self, "About AllMyNotes",
                "The <b>Dock Widgets</b> example demonstrates how to use "
                "Qt's dock widgets. You can enter your own text, click a "
                "customer to add a customer name and address, and click "
                "standard paragraphs to add them." )
